# todo:给定一段英文文本（单词间都是空格分隔），请编写一个函数，将每个单词的首字母转成大写。
# 输入: "auto school of witchcraft and wizardry"
# 输出: "Auto School Of Witchcraft And Wizardry"
# str_01 = "auto school of witchcraft and wizardry"
# str_new = " ".join([i.capitalize() for i in str_01.split()])
# print(str_new)
import json

# str_01 = "auto school of witchcraft and wizardry"
# str_new = " "
# for i in str_01.split():
#     str_new += i.capitalize() + " "
# print(str_new)

# todo:给定一个字符串，将它们其中的每个字符（区分大小写）再重复一次。
# 输入: "Hello World"
# 输出: "HHeelllloo  WWoorrlldd"
# str_01 = "Hello World"
# str_new = []
# for i in str_01:
#     str_new+= i*2
# print("".join(str_new))

# todo:给定一个字符串，将其中的每个单词的字母顺序进行反转。空格的个数不定，记得需要保留所有的空格，请编写一个python函数
# 输入: "hello  world"
# 输出: "olleh  dlrow"
# str_01 = "hello  world"
# str_new = []
# for i in str_01.split():
#     str_new.append(i[::-1])
# print(" ".join(str_new))

# todo:请输出1-1000的数字如下格式
# 输入: 1、2、99
# 输出: 0001、0002、0099
# str_01 = [1,2,99]
# str_new = []
# for i in str_01:
#     str_new.append(f"{i:04d}")
# print(str_new)

# str_01 = "1、2、99"
# print (" ".join([i.zfill(4) for i in str_01.split("、")]))

# a = "1、22、99"
# print(("000" + str(a))[-4:])

# todo: 单词都是重复的，字符串去重
# 输入: "Wingardium Leviosa Wingardium Leviosa Expelliarmus Leviosa Expelliarmus"
# 输出: "Wingardium Leviosa Expelliarmus"
# from collections import OrderedDict
# str_01 = "Wingardium Leviosa Wingardium Leviosa Expelliarmus Leviosa Expelliarmus"
# # str_new = str_01.split()
# unique_words = " ".join(OrderedDict.fromkeys(str_new))
# print(unique_words)

# from collections import OrderedDict
# str_01 = "Wingardium Leviosa Wingardium Leviosa Expelliarmus Leviosa Expelliarmus"
# print(" ".join(OrderedDict.fromkeys(str_01.split())))

# todo: 输入一个字符串，打印出该字符串中字符的所有排列，可以以任意顺序返回这个字符串数组，但里面不能有重复元素。
#  输入: s = "abc"
#  输出: ["abc","acb","bac","bca","cab","cba"]


# todo: 给定一个数字列表，其中每个元素都是正整数。请编写一个函数，将列表整体所代表的数字加1，然后返回成新列表。
#  输入：[2, 3, 9]，输出：[2, 4, 0]
#  输入：[4, 3, 2, 5]，输出：[4, 3, 2, 6]


# todo: 写json文件
# import json
#
# list_data = []
# with open("./object_07_FilesDemo.txt", encoding='utf-8')  as f:
#     for i in f.readlines():
#         if "辽宁省" in i:
#          datas = i.split()
#          dict_data = {
#                 "name": datas[0],
#                 "address": datas[1],
#                 "id": datas[2],
#          }
#          list_data.append(dict_data)
# with open("./object_07_FilesDemo.json", mode="w",encoding='utf-8') as f:
#     json.dump(list_data,f,ensure_ascii=False,indent=4)

# todo: 日志
# import json
#
# with open("./test_case.log","r",encoding="utf-8") as f:
#     lines = f.readlines()
#     business = {"request":"","response":""}
#     for i in lines:
#         bus_data = i.split("执行方法:")[1]
#         if "creditApply" in bus_data and "请求参数：" in bus_data:
#             data = bus_data.split("请求参数：")[1]
#             json_data = json.loads(data)
#             json_data.update({"params":json.loads(json_data["params"])})
#             business["request"] = json_data
# with open("./test_creditApply.json","w",encoding="utf-8") as f:
#    json.dump(business, f, ensure_ascii=False,indent=2)

import json

business = ("creditApply", "creditQuery")
for item in business:
    with open("./test_case.log", "r", encoding="utf-8") as f:
        lines = f.readlines()
        for line in lines:
            if "请求参数: " in line and item in line:
                data = line.split("请求参数:")[1]
                request_data = json.loads(data)
                request_data.update({"params": json.load(request_data.get("params"))})
            if "res=" in line and item in line:
                data = line.split("res=")[1]
                request_data = json.loads(data)
                request_data.update({"params": json.load(request_data("params"))})
            api_data = {"request": request_data, "response": request_data}
    with open("./test_case.json", "w", encoding="utf-8") as f:
        json.dump(api_data, f, ensure_ascii=False)